<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="cn.lh.spider.entity.Filter,cn.lh.spider.entity.Task,java.util.*" isELIgnored="false"%>
    <%
    	Task task =(Task)request.getAttribute("task");
    	String taskid = task.getId();
    	
    	
    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
	
	<%=request.getAttribute("titletab")%>
	<%=request.getAttribute("contenttab")%>
	<%=request.getAttribute("datetab")%>
	//alert(JSON.stringify(urltab));
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
	<link rel="stylesheet" type="text/css" href="/gaspider/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="/gaspider/easyui/themes/icon.css">
	<script type="text/javascript" src="/gaspider/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="/gaspider/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="/gaspider/easyui/locale/easyui-lang-zh_CN.js"></script>
	<style type="text/css">
		*{
			margin:0;
			padding:0;
		}
		html,body{
			height:100%;
			width:100%;
		}
		.content{
			height:60px;
			font-size:14px;
			margin-top:10px; 
		}
		.content1{
		    font-size:14px;
			margin-top:10px; 
		}
		.title{
		    font-family: "Microsoft YaHei",华文细黑,微软雅黑,文鼎简报宋;
			height:26px;
			background-color:#f3f3f3;
		}
table{
font-size:12px;
table-layout:fixed;
empty-cells:show;
border-collapse: collapse;
width:92%;
/* margin:0 auto; */
}
td{
text-overflow: ellipsis; 
white-space: nowrap; 
overflow: hidden;
height:30px;
}

.table{
border:1px solid #cad9ea;
color:#666;
}
.table th {
background-repeat:repeat-x;
height:30px;
}
.table td,.table th{
border:1px solid #cad9ea;
padding:0 1em 0;
}
.table tr.alter{
background-color:#f5fafe;
}
.adv,.adq{
	float:right;
}
.color{border:2px solid #D6DDE3;}
.color1{border:2px solid #A6C8FF;}

	</style>
</head>
<body>
	
	<div class="title">
		采集关键词
	</div>
	<div class="content">
		<div>
			<label>文章类型:&nbsp</label><input  id="articletype" type="text" value="${task.articletype }" style="width:250px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			<label>网站名称:</label><input  id="websitename" type="text" value="${task.websitename }" style="width:293px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
		</div>
		<div style="margin-left:5px; margin-top:5px;">
			<label>入口url:&nbsp</label><input  id="entryurl" type="text" value="${task.entryurl }" style="width:725px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
		</div>
		
	</div>
	<div class="title">
		过滤规则配置
	</div>
	<div class="content1">
		<div style="margin-top:5px;">
			<label>列表页规则:&nbsp</label><input  id="listsrule" type="text" value="${task.listsrule }" style="width:235px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
		    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			<label>列表页正则:&nbsp</label><input  id="listsrex" type="text" value="${task.listsrex }" style="width:270px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
		</div>
		
		<div style="margin-top:5px;">
			<label>原文url抽取规则:&nbsp</label><input  id="urlrex" type="text" value="${task.urlrex }" style="width:200px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			<label>文章页规则:&nbsp</label><input  id="writingrule" type="text" value="${task.writingrule }" style="width:270px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
		</div>
		
		<div style="margin-top:5px;">
			<label>文章页正则:&nbsp</label><input  id="writingrex" type="text" value="${task.writingrex }" style="width:235px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			<label>分页规则:&nbsp</label><input  id="pagerule" type="text" value="${task.pagerule }" style="width:285px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
		</div>
		
		<div style="margin-top:5px;">
			<label>分页正则:&nbsp</label><input  id="pagerex" type="text" value="${task.pagerex }" style="width:248px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			<label>分页后缀:&nbsp</label><input  id="pagesuffix" type="text" value="${task.pagesuffix }" style="width:285px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
		</div>
	
		<div style="margin-top:5px;">
			<label>标题抽取规则:&nbsp</label><input  id="titlerule" type="text" value="${task.titlerule }" style="width:221px; height:20px;" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			<label>标题过滤规则:&nbsp</label><input  id="titlefilter" type="text" style="width:225px; height:20px;" class="easyui-validatebox color" onmouseout="this.className='color'" onmousemove="this.className='color1'"/><button onclick="titleins()">增加</button>
		</div>
		<table id="titletab" class="table" style="margin-top:5px;">
			<tr class="alter">
				<th width="10px">顺序</th>
				<th width="100px">title过滤规则</th>
				<th width="10px"></th>
			</tr>
		</table>
		<div style="margin-top:5px;">
			<label>正文抽取规则:&nbsp</label><input  id="contentrule" type="text" style="width:225px; height:20px;" value="${task.contentrule}" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			<label>正文过滤规则:&nbsp</label><input  id="contentfilter" type="text" style="width:225px; height:20px;" class="easyui-validatebox color" onmouseout="this.className='color'" onmousemove="this.className='color1'"/><button onclick="contentins()">增加</button>
		</div>
		<table id="contenttab" class="table" style="margin-top:5px;">
			<tr class="alter">
				<th width="10px">顺序</th>
				<th width="100px">正文过滤规则</th>
				<th width="10px"></th>
			</tr>
			
		</table>
		
		<div style="margin-top:5px;">
			<label>发表日期抽取规则:&nbsp</label><input  id="releasedaterule" type="text" style="width:195px; height:20px;" value="${task.releasedaterule }" class="easyui-validatebox color" novalidate="true" required="true" onmouseout="this.className='color'" onmousemove="this.className='color1'"/>
			&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			<label>发表日期过滤规则:&nbsp</label><input  id="releasedatefilter" type="text" style="width:199px; height:20px;" class="easyui-validatebox color" onmouseout="this.className='color'" onmousemove="this.className='color1'"/><button onclick="dateins()">增加</button>
		</div>
		<table id="datetab" class="table" style="margin-top:5px;">
			<tr class="alter">
				<th width="10px">顺序</th>
				<th width="100px">发表日期过滤规则</th>
				<th width="10px"></th>
			</tr>
		</table>
		
	</div>
	
<div style="float:right;">
	     <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="submit()">确定</a>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="submit(0)">取消</a>
	
	</div>
</body>
</html>
<script>

	
				if(titletab.length>0){
					var html = "";
					for(var m=0;m<titletab.length;m++){
						delete titletab[m].id;
						delete titletab[m].referenceid;
						html = html +'<tr class="alter"><td>'+titletab[m].torder+'</td><td>'+titletab[m].filter+'</td><td>'+'<a href="javascript:void(0);" onclick="titledel('+m+')">删除</a>'+'</td></tr>';
						
					}
					$("#titletab").append(html);
				}
				if(contenttab.length>0){
					var html = "";
					for(var m=0;m<contenttab.length;m++){
						delete contenttab[m].id;
						delete contenttab[m].referenceid;
						html = html +'<tr class="alter"><td>'+contenttab[m].torder+'</td><td>'+contenttab[m].filter+'</td><td>'+'<a href="javascript:void(0);" onclick="contentdel('+m+')">删除</a>'+'</td></tr>';
						
					}
					$("#contenttab").append(html);
				}
				if(datetab.length>0){
					var html = "";
					for(var m=0;m<datetab.length;m++){
						delete datetab[m].id;
						delete datetab[m].referenceid;
						html = html +'<tr class="alter"><td>'+datetab[m].torder+'</td><td>'+datetab[m].filter+'</td><td>'+'<a href="javascript:void(0);" onclick="datedel('+m+')">删除</a>'+'</td></tr>';
						
					}
					$("#datetab").append(html);
				}
			</script>
<script>
	function submit(r){
		if(r==0){
			window.parent.$('#win').window('close');
		}else{
			//校验有问题
			$('.easyui-validatebox').validatebox('enableValidation');
			var v = $('.easyui-validatebox').validatebox('isValid');
			if(v){
				//拿出非表格数据，表格数据拿出来提交到后台要处理然后进行数据库操作
				var jsonform = {
						"id":'<%=taskid%>',
						"articletype":$('#articletype').val(),
						"websitename":$('#websitename').val(),
						"entryurl":$('#entryurl').val(),
						"taskstate":$('#taskstate').val(),
						"listsrule":$('#listsrule').val(),
					 	"listsrex":$('#listsrex').val(),
					 	"writingrule":$('#writingrule').val(),
					 	"writingrex":$('#writingrex').val(),
					 	"writingrex":$('#writingrex').val(),
						"urlrex":$('#urlrex').val(), 
						"pagerule":$('#pagerule').val(), 
						"pagerex":$('#pagerex').val(), 
						"pagesuffix":$('#pagesuffix').val(), 
						"titlerule":$('#titlerule').val(),
						"titlefilter":titletab,
						"contentrule":$('#contentrule').val(),
						"contentfilter":contenttab,
						"releasedaterule":$('#releasedaterule').val(),
						"releasedatefilter":datetab
				}
				$.ajax({
					url: '/gaspider/task/edittask.do',
					type: "post",
					data: jsonform,
					success: function(result){
						if (!result.success){
							window.parent.$.messager.show({
								title:'消息',
								msg:'修改失败。',
								timeout:1000,
								showType:'slide'
							});
							
						}else{
							window.parent.$.messager.show({
								title:'消息',
								msg:'修改成功。',
								timeout:1000,
								showType:'slide'
							});
						}
						console.log(window.location.href)
						console.log(window.parent.location.href)
						window.parent.$('#dg').datagrid('reload');
						window.parent.$('#dg').datagrid('clearChecked');
						window.parent.$('#win').window('close');
						
						
						
					} 
				});
				
			}
		}
	}

var titlenum = titletab.length+1;
var contentnum = contenttab.length+1;
var datenum = datetab.length+1;

function titleins(){
	var inputs = $('#titlefilter').val();
	if(inputs==""){
		alert('请输入过滤值')
	}else{
		var tabjson = {
				"torder":titlenum,
				"filter":inputs
		}
		titletab.push(tabjson);
		console.log(titletab);
	//增加table内容
		var html ='<tr class="alter"><td>'+titlenum+'</td><td>'+inputs+'</td><td>'+'<a href="javascript:void(0);" onclick="titledel('+(titletab.length-1)+')">删除</a>'+'</td></tr>';
		$("#titletab").append(html);
		titlenum=titlenum+1;
	}
}
function titledel(id){
	//构造新的json字符串
	titletab.splice(id,1);
	titlenum=titlenum-1;
	console.log(titletab);
	//删掉table内容,更新table内容
	var html='<tr class="alter"><th width="10px">顺序</th><th width="100px">title过滤规则</th><th width="10px"></th></tr>';
	for(var i=0;i<titletab.length;i++){
		titletab[i].order=i+1;
		html=html+'<tr class="alter"><td>'+titletab[i].torder+'</td><td>'+titletab[i].filter+'</td><td>'+'<a href="javascript:void(0);" onclick="titledel('+i+')">删除</a>'+'</td></tr>';
	}
	$("#titletab").html(html);
}
function contentins(){
	var inputs = $('#contentfilter').val();
	if(inputs==""){
		alert('请输入过滤值')
	}else{
		var tabjson = {
				"torder":contentnum,
				"filter":inputs
		}
		contenttab.push(tabjson);
		console.log(contenttab);
	//增加table内容
		var html ='<tr class="alter"><td>'+contentnum+'</td><td>'+inputs+'</td><td>'+'<a href="javascript:void(0);" onclick="contentdel('+(contenttab.length-1)+')">删除</a>'+'</td></tr>';
		$("#contenttab").append(html);
		contentnum=contentnum+1;
	}
}
function contentdel(id){
	//构造新的json字符串
	contenttab.splice(id,1);
	contentnum=contentnum-1;
	console.log(contenttab);
	//删掉table内容,更新table内容
	var html='<tr class="alter"><th width="10px">顺序</th><th width="100px">正文过滤规则</th><th width="10px"></th></tr>';
	for(var i=0;i<contenttab.length;i++){
		contenttab[i].order=i+1;
		html=html+'<tr class="alter"><td>'+contenttab[i].torder+'</td><td>'+contenttab[i].filter+'</td><td>'+'<a href="javascript:void(0);" onclick="contentdel('+i+')">删除</a>'+'</td></tr>';
	}
	$("#contenttab").html(html);
}
function dateins(){
	var inputs = $('#releasedatefilter').val();
	if(inputs==""){
		alert('请输入过滤值')
	}else{
		var tabjson = {
				"torder":datenum,
				"filter":inputs
		}
		datetab.push(tabjson);
		console.log(datetab);
	//增加table内容
		var html ='<tr class="alter"><td>'+datenum+'</td><td>'+inputs+'</td><td>'+'<a href="javascript:void(0);" onclick="datedel('+(datetab.length-1)+')">删除</a>'+'</td></tr>';
		$("#datetab").append(html);
		datenum=datenum+1;
	}
}
function datedel(id){
	//构造新的json字符串
	datetab.splice(id,1);
	datenum=datenum-1;
	console.log(datetab);
	//删掉table内容,更新table内容
	var html='<tr class="alter"><th width="10px">顺序</th><th width="100px">发布日期过滤规则</th><th width="10px"></th></tr>';
	for(var i=0;i<datetab.length;i++){
		datetab[i].order=i+1;
		html=html+'<tr class="alter"><td>'+datetab[i].torder+'</td><td>'+datetab[i].filter+'</td><td>'+'<a href="javascript:void(0);" onclick="datedel('+i+')">删除</a>'+'</td></tr>';
	}
	$("#datetab").html(html);
}
</script>
